voicemeeter\interface\parameters/
bus.rs

1//! Bus parameters
2use super::*;
3
4/// Parameters for a bus.
5///
6/// A bus is a output.
7///
8/// Returned by [`VoicemeeterRemote::parameters().bus(i)`](VoicemeeterRemote::parameters)
9///
10///
11/// # Example
12///
13/// ```rust,no_run
14/// use voicemeeter::VoicemeeterRemote;
15///
16/// // Get the client.
17/// let remote = VoicemeeterRemote::new()?;
18///
19/// // Get the label of bus A1 (index 0)
20/// println!("{}", remote.parameters().bus(0)?.label().get()?);
21///
22/// // Mute bus A4 (index 5)
23/// remote.parameters().bus(2)?.mute().set(true)?;
24///
25/// // Ensure the change is registered.
26/// remote.is_parameters_dirty()?;
27///
28/// // We need to sleep here because otherwise changes won't be registered,
29/// // in a long running program this is not needed.
30/// std::thread::sleep(std::time::Duration::from_millis(50));
31///
32/// # Ok::<(), Box<dyn std::error::Error>>(())
33/// ```
34pub struct Bus<'a> {
35    remote: &'a VoicemeeterRemote,
36    bus_index: ZIndex,
37}
38
39impl<'a> Bus<'a> {
40    #[doc(hidden)]
41    pub fn new(remote: &'a VoicemeeterRemote, bus_index: ZIndex) -> Self {
42        Bus { remote, bus_index }
43    }
44
45    /// Get the identifier for a parameter on this bus: `Bus[i].{dot}`
46    pub fn param(&self, dot: impl ToString) -> Cow<'static, ParameterNameRef> {
47        // TODO: Should this maybe allow custom names?
48        Cow::Owned(format!("{BUS}[{}].{}", self.bus_index, dot.to_string()).into())
49    }
50
51    /// Label
52    pub fn label(&self) -> StringParameter<'_> {
53        StringParameter::new(self.param("Label"), self.remote)
54    }
55
56    /// Mono Button
57    pub fn mono(&self) -> IntParameter<'_> {
58        IntParameter::new(self.param("Mono"), self.remote, 0..=2)
59    }
60
61    /// Mute Button
62    pub fn mute(&self) -> BoolParameter<'_> {
63        BoolParameter::new(self.param("Mute"), self.remote)
64    }
65
66    /// EQ Button
67    pub fn eq_on(&self) -> BoolParameter<'_> {
68        BoolParameter::new(self.param("EQ.on"), self.remote)
69    }
70
71    /// EQ Memory Slot
72    pub fn eq_ab(&self) -> BoolParameter<'_> {
73        BoolParameter::new(self.param("EQ.AB"), self.remote)
74    }
75
76    /// Gain slider
77    pub fn gain(&self) -> FloatParameter<'_> {
78        FloatParameter::new(self.param("gain"), self.remote, -60.0..=12.)
79    }
80
81    /// Bus mode Normal
82    pub fn mode(&self) -> BusModeParameter<'_> {
83        BusModeParameter::new(self.remote, self.bus_index)
84    }
85
86    /// EQ on channel
87    pub fn eq(&self, channel: usize) -> EqChannelParameter<'_> {
88        EqChannelParameter::new_bus(self.remote, self.bus_index, channel)
89    }
90    /// Fade to
91    pub fn fade_to(&self) -> TupleParameter<'_, f32, usize> {
92        TupleParameter::new(self.param("FadeTo"), self.remote)
93    }
94    /// Fade by
95    pub fn fade_by(&self) -> TupleParameter<'_, f32, usize> {
96        TupleParameter::new(self.param("FadeBy"), self.remote)
97    }
98    /// BUS SEL Button
99    pub fn sel(&self) -> BoolParameter<'_> {
100        BoolParameter::new(self.param("Sel"), self.remote)
101    }
102    /// Reverb return
103    pub fn return_reverb(&self) -> IntParameter<'_> {
104        IntParameter::new(self.param("ReturnReverb"), self.remote, 0..=10)
105    }
106    /// Delay return
107    pub fn return_delay(&self) -> IntParameter<'_> {
108        IntParameter::new(self.param("ReturnDelay"), self.remote, 0..=10)
109    }
110    /// Fx1 Return
111    pub fn return_fx1(&self) -> IntParameter<'_> {
112        IntParameter::new(self.param("ReturnFx1"), self.remote, 0..=10)
113    }
114    /// Fx2 Return
115    pub fn return_fx2(&self) -> IntParameter<'_> {
116        IntParameter::new(self.param("ReturnFx2"), self.remote, 0..=10)
117    }
118    /// Monitor
119    pub fn monitor(&self) -> BoolParameter<'_> {
120        BoolParameter::new(self.param("Monitor"), self.remote)
121    }
122    /// Audio Device information
123    pub fn device(&self) -> BusDevice<'_> {
124        BusDevice::new(self.remote, self.bus_index)
125    }
126
127    /// VAIO output enable/disable.
128    ///
129    /// # Notes requires VAIO extension
130    pub fn vaio(&self) -> BoolParameter<'_> {
131        BoolParameter::new(self.param("VAIO"), self.remote)
132    }
133}
134
135/// Parameters for bus mode
136pub struct BusModeParameter<'a> {
137    remote: &'a VoicemeeterRemote,
138    bus_index: ZIndex,
139}
140
141impl<'a> BusModeParameter<'a> {
142    fn new(remote: &'a VoicemeeterRemote, bus_index: ZIndex) -> Self {
143        Self { remote, bus_index }
144    }
145
146    /// Get the identifier for a mode parameter on this bus: `Bus[i].mode.{dot}`
147    pub fn param(&self, dot: impl ToString) -> Cow<'static, ParameterNameRef> {
148        // TODO: Should this maybe allow custom names?
149        Cow::Owned(format!("{BUS}[{}].mode.{}", self.bus_index, dot.to_string()).into())
150    }
151
152    /// Get the current bus mode
153    pub fn get(&self) -> Result<Option<BusMode>, GetParameterError> {
154        Ok(Some(if self.is_normal()? {
155            BusMode::Normal
156        } else if self.is_amix()? {
157            BusMode::Amix
158        } else if self.is_bmix()? {
159            BusMode::Bmix
160        } else if self.is_repeat()? {
161            BusMode::Repeat
162        } else if self.is_composite()? {
163            BusMode::Composite
164        } else if self.is_tv_mix()? {
165            BusMode::TvMix
166        } else if self.is_up_mix21()? {
167            BusMode::UpMix21
168        } else if self.is_up_mix41()? {
169            BusMode::UpMix41
170        } else if self.is_up_mix61()? {
171            BusMode::UpMix61
172        } else if self.is_center_only()? {
173            BusMode::CenterOnly
174        } else if self.is_lfe_only()? {
175            BusMode::LfeOnly
176        } else if self.is_rear_only()? {
177            BusMode::RearOnly
178        } else {
179            return Ok(None);
180        }))
181    }
182    /// Set the bus mode
183    pub fn set(&self, mode: BusMode) -> Result<(), SetParameterError> {
184        match mode {
185            BusMode::Normal => self.set_normal(true),
186            BusMode::Amix => self.set_amix(true),
187            BusMode::Bmix => self.set_bmix(true),
188            BusMode::Repeat => self.set_repeat(true),
189            BusMode::Composite => self.set_composite(true),
190            BusMode::TvMix => self.set_tv_mix(true),
191            BusMode::UpMix21 => self.set_up_mix21(true),
192            BusMode::UpMix41 => self.set_up_mix41(true),
193            BusMode::UpMix61 => self.set_up_mix61(true),
194            BusMode::CenterOnly => self.set_center_only(true),
195            BusMode::LfeOnly => self.set_lfe_only(true),
196            BusMode::RearOnly => self.set_rear_only(true),
197        }
198    }
199
200    /// Returns `true` if the bus mode is [`Normal`](BusMode::Normal)
201    pub fn is_normal(&self) -> Result<bool, GetParameterError> {
202        BoolParameter::<'_, false, true>::new(self.param("normal"), self.remote).get()
203    }
204    /// Returns `true` if the bus mode is [`Amix`](BusMode::Amix)
205    pub fn is_amix(&self) -> Result<bool, GetParameterError> {
206        BoolParameter::<'_, false, true>::new(self.param("Amix"), self.remote).get()
207    }
208    /// Returns `true` if the bus mode is [`Bmix`](BusMode::Bmix)
209    pub fn is_bmix(&self) -> Result<bool, GetParameterError> {
210        BoolParameter::<'_, false, true>::new(self.param("Bmix"), self.remote).get()
211    }
212    /// Returns `true` if the bus mode is [`Repeat`](BusMode::Repeat)
213    pub fn is_repeat(&self) -> Result<bool, GetParameterError> {
214        BoolParameter::<'_, false, true>::new(self.param("Repeat"), self.remote).get()
215    }
216    /// Returns `true` if the bus mode is [`Composite`](BusMode::Composite)
217    pub fn is_composite(&self) -> Result<bool, GetParameterError> {
218        BoolParameter::<'_, false, true>::new(self.param("Composite"), self.remote).get()
219    }
220    /// Returns `true` if the bus mode is [`TvMix`](BusMode::TvMix)
221    pub fn is_tv_mix(&self) -> Result<bool, GetParameterError> {
222        BoolParameter::<'_, false, true>::new(self.param("TVMix"), self.remote).get()
223    }
224    /// Returns `true` if the bus mode is [`UpMix21`](BusMode::UpMix21)
225    pub fn is_up_mix21(&self) -> Result<bool, GetParameterError> {
226        BoolParameter::<'_, false, true>::new(self.param("UpMix21"), self.remote).get()
227    }
228    /// Returns `true` if the bus mode is [`UpMix41`](BusMode::UpMix41)
229    pub fn is_up_mix41(&self) -> Result<bool, GetParameterError> {
230        BoolParameter::<'_, false, true>::new(self.param("UpMix41"), self.remote).get()
231    }
232    /// Returns `true` if the bus mode is [`UpMix61`](BusMode::UpMix61)
233    pub fn is_up_mix61(&self) -> Result<bool, GetParameterError> {
234        BoolParameter::<'_, false, true>::new(self.param("UpMix61"), self.remote).get()
235    }
236    /// Returns `true` if the bus mode is [`CenterOnly`](BusMode::CenterOnly)
237    pub fn is_center_only(&self) -> Result<bool, GetParameterError> {
238        BoolParameter::<'_, false, true>::new(self.param("CenterOnly"), self.remote).get()
239    }
240    /// Returns `true` if the bus mode is [`LfeOnly`](BusMode::LfeOnly)
241    pub fn is_lfe_only(&self) -> Result<bool, GetParameterError> {
242        BoolParameter::<'_, false, true>::new(self.param("LFEOnly"), self.remote).get()
243    }
244    /// Returns `true` if the bus mode is [`RearOnly`](BusMode::RearOnly)
245    pub fn is_rear_only(&self) -> Result<bool, GetParameterError> {
246        BoolParameter::<'_, false, true>::new(self.param("RearOnly"), self.remote).get()
247    }
248
249    /// Set the bus mode for [`Normal`](BusMode::Normal)
250    pub fn set_normal(&self, val: bool) -> Result<(), SetParameterError> {
251        BoolParameter::<'_, true, false>::new(self.param("normal"), self.remote).set(val)
252    }
253    /// Set the bus mode for [`Amix`](BusMode::Amix)
254    pub fn set_amix(&self, val: bool) -> Result<(), SetParameterError> {
255        BoolParameter::<'_, true, false>::new(self.param("Amix"), self.remote).set(val)
256    }
257    /// Set the bus mode for [`Bmix`](BusMode::Bmix)
258    pub fn set_bmix(&self, val: bool) -> Result<(), SetParameterError> {
259        BoolParameter::<'_, true, false>::new(self.param("Bmix"), self.remote).set(val)
260    }
261    /// Set the bus mode for [`Repeat`](BusMode::Repeat)
262    pub fn set_repeat(&self, val: bool) -> Result<(), SetParameterError> {
263        BoolParameter::<'_, true, false>::new(self.param("Repeat"), self.remote).set(val)
264    }
265    /// Set the bus mode for [`Composite`](BusMode::Composite)
266    pub fn set_composite(&self, val: bool) -> Result<(), SetParameterError> {
267        BoolParameter::<'_, true, false>::new(self.param("Composite"), self.remote).set(val)
268    }
269    /// Set the bus mode for [`TvMix`](BusMode::TvMix)
270    pub fn set_tv_mix(&self, val: bool) -> Result<(), SetParameterError> {
271        BoolParameter::<'_, true, false>::new(self.param("TVMix"), self.remote).set(val)
272    }
273    /// Set the bus mode for [`UpMix21`](BusMode::UpMix21)
274    pub fn set_up_mix21(&self, val: bool) -> Result<(), SetParameterError> {
275        BoolParameter::<'_, true, false>::new(self.param("UpMix21"), self.remote).set(val)
276    }
277    /// Set the bus mode for [`UpMix41`](BusMode::UpMix41)
278    pub fn set_up_mix41(&self, val: bool) -> Result<(), SetParameterError> {
279        BoolParameter::<'_, true, false>::new(self.param("UpMix41"), self.remote).set(val)
280    }
281    /// Set the bus mode for [`UpMix61`](BusMode::UpMix61)
282    pub fn set_up_mix61(&self, val: bool) -> Result<(), SetParameterError> {
283        BoolParameter::<'_, true, false>::new(self.param("UpMix61"), self.remote).set(val)
284    }
285    /// Set the bus mode for [`CenterOnly`](BusMode::CenterOnly)
286    pub fn set_center_only(&self, val: bool) -> Result<(), SetParameterError> {
287        BoolParameter::<'_, true, false>::new(self.param("CenterOnly"), self.remote).set(val)
288    }
289    /// Set the bus mode for [`LfeOnly`](BusMode::LfeOnly)
290    pub fn set_lfe_only(&self, val: bool) -> Result<(), SetParameterError> {
291        BoolParameter::<'_, true, false>::new(self.param("LFEOnly"), self.remote).set(val)
292    }
293    /// Set the bus mode for [`RearOnly`](BusMode::RearOnly)
294    pub fn set_rear_only(&self, val: bool) -> Result<(), SetParameterError> {
295        BoolParameter::<'_, true, false>::new(self.param("RearOnly"), self.remote).set(val)
296    }
297}
298
299/// Bus device parameters
300pub struct BusDevice<'a> {
301    remote: &'a VoicemeeterRemote,
302    bus_index: ZIndex,
303}
304
305impl<'a> BusDevice<'a> {
306    #[doc(hidden)]
307    pub fn new(remote: &'a VoicemeeterRemote, bus_index: ZIndex) -> Self {
308        Self { remote, bus_index }
309    }
310
311    /// Get the identifier for a device parameter on this bus: `Bus[i].device.{dot}`
312    pub fn param(&self, dot: impl ToString) -> Cow<'static, ParameterNameRef> {
313        Cow::Owned(format!("{BUS}[{}].device.{}", self.bus_index, dot.to_string()).into())
314    }
315    /// Name of the device.
316    pub fn name(&self) -> StringParameter<'a, false, true> {
317        StringParameter::new(self.param("name"), self.remote)
318    }
319    /// Samplerate of the device.
320    pub fn sr(&self) -> IntParameter<'a, false, true> {
321        IntParameter::new_unranged(self.param("sr"), self.remote)
322    }
323    /// WDM device
324    pub fn wdm(&self) -> StringParameter<'a, true, false> {
325        StringParameter::new(self.param("wdm"), self.remote)
326    }
327    /// KS device
328    pub fn ks(&self) -> StringParameter<'a, true, false> {
329        StringParameter::new(self.param("ks"), self.remote)
330    }
331    /// MME device
332    pub fn mme(&self) -> StringParameter<'a, true, false> {
333        StringParameter::new(self.param("mme"), self.remote)
334    }
335    /// ASIO device
336    pub fn asio(&self) -> StringParameter<'a, true, false> {
337        StringParameter::new(self.param("asio"), self.remote)
338    }
339}